﻿using FBroSharp.Const;
using FBroSharp.DataType;
using FBroSharp.VIP;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VIP指纹测试
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //创建浏览器
            BrowserDis.CreatBrowser("百度", "www.baidu.com", this.Handle, 0, this.menuStrip1.Height, this.ClientSize.Width, this.ClientSize.Height);
        }
        private void Form1_Resize(object sender, EventArgs e)
        {
            for (int i = 0; i < BrowserList.data.Count; i++)
            {
                BrowserList.data[i].MoveWindow(0, this.menuStrip1.Height, this.ClientSize.Width, this.ClientSize.Height, true);

            }
        }
    
        private void 测试地址1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().LoadURL("https://gongjux.com/fingerprint/");
        }

        private void 测试地址2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().LoadURL("https://www.browserscan.net/bot-detection");
        }

        private void 测试地址3ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().LoadURL("https://yisin.gitee.io/ysfile/checkbrowser.html");
        }

        private void 测试地址4ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().LoadURL("https://www.yalala.com/");
        }

        private void 测试地址5ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().LoadURL("https://browserleaks.com/webrtc");
        }

        private void 测试地址6ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().LoadURL("https://abrahamjuliot.github.io/creepjs/");
        }

        private void 测试地址7ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().LoadURL("https://browserleaks.com/webgl");
        }

        private void 测试地址8ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().LoadURL("http://f.vision/");
        }

        private void 指纹刷新VIPToolStripMenuItem_Click(object sender, EventArgs e)
        {

            //修改指纹
            BrowserDis.ChangeFingerPrint(BrowserList.data[0]);

            BrowserList.data[0].ReloadIgnoreCache();
        }

        private void 修改内容ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //全局方式
            //FBroSharpVIPControl.ResponseFilterAddChangeData(FBroSharpResponseURLFindType.ALL, "https://www.baidu.com/",
            //    FBroSharpResponseFilterType.ChangeAllData, "百度", "FBrowserCEF3Lib");

            //按浏览器
            var con = BrowserList.data[0].GetVIPControl();
            con.ResponseFilterAddChangeData(FBroSharpResponseURLFindType.ALL, "https://www.baidu.com/",
                FBroSharpResponseFilterType.ChangeAllData, "百度", "FBrowserCEF3Lib");
            con.ResponseFilterAddChangeData(FBroSharpResponseURLFindType.ALL, "https://www.baidu.com/",
                FBroSharpResponseFilterType.ChangeAllData, "About Baidu", "About FBrowser");
            BrowserList.data[0].ReloadIgnoreCache();
        }

        private void 取消修改内容ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //全局方式
            //FBroSharpVIPControl.ResponseFilterDeleteChangeData("https://www.baidu.com/");

            //按浏览器
            BrowserList.data[0].GetVIPControl().ResponseFilterDeleteChangeData("https://www.baidu.com/");
            BrowserList.data[0].ReloadIgnoreCache();
        }

        private void 用数据替换资源ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            const string soure = @"<html> <head>
                              <meta charset=""UTF-8"">
                              <title>Test Cef</title>
                            </head>
                            <body bgcolor= ""white"">
                            <h2>你好FBrowser！！！</h2>
                            <a style='color:#00ff00'>这是一个直接将百度网页直接替换掉的例子！</a>
                            <div style='color:red'>这里是个div</div>
                            <a href='https://www.baidu.com'>打开百度网页(其实你永远都打不开，哈哈)</a>
                            </body>
                            <script>alert('你好FBrowser')</script></html>";

            //资源协议头
            //FBroSharpStringMap[] header_map = new FBroSharpStringMap[1];
            //header_map[0].key = "content-encoding";
            //header_map[0].value = "gzip";

            //全局方式
            //FBroSharpVIPControl.ResourceHandlerAddChangeData(FBroSharpResponseURLFindType.ALL, "https://www.baidu.com/", "text/html", default/*header_map*/,
            //    System.Text.Encoding.UTF8.GetBytes(soure));

            //按浏览器
            BrowserList.data[0].GetVIPControl().ResourceHandlerAddChangeData(FBroSharpResponseURLFindType.ALL, "https://www.baidu.com/", "text/html", default/*header_map*/,
                System.Text.Encoding.UTF8.GetBytes(soure));
            BrowserList.data[0].ReloadIgnoreCache();
        }

        private void 用本地文件替换资源ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //资源协议头
            FBroSharpStringMap[] header_map = new FBroSharpStringMap[1];
            header_map[0].key = "content-encoding";
            header_map[0].value = "gzip";

            //全局方式
            //FBroSharpVIPControl.ResourceHandlerAddChangeFile(FBroSharpResponseURLFindType.ALL, "https://www.baidu.com/", "application/javascript", header_map,
            //   Directory.GetCurrentDirectory() + "\\..\\..\\html\\t.js");

            //按浏览器
            BrowserList.data[0].GetVIPControl().ResourceHandlerAddChangeFile(FBroSharpResponseURLFindType.ALL, "https://www.baidu.com/", "application/javascript", header_map,
               Directory.GetCurrentDirectory() + "\\..\\..\\html\\t.js");

            BrowserList.data[0].ReloadIgnoreCache();
        }

        private void 取消替换资源ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //全局方式
            //FBroSharpVIPControl.ResourceHandlerDeleteChangeData("https://www.baidu.com/");

            //按浏览器
            BrowserList.data[0].GetVIPControl().ResourceHandlerDeleteChangeData("https://www.baidu.com/");

            BrowserList.data[0].ReloadIgnoreCache();
        }

        private void tLSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().LoadURL("https://browserleaks.com/tls");
        }

        private void 获取指纹调用数ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var control = BrowserList.data[0].GetVIPControl();
            if (control.IsValid)
            {
                Console.WriteLine(control.GetFingerPrintControl().GetFingerCount());
            }
        }

        private void 清空指纹调用数ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var control = BrowserList.data[0].GetVIPControl();
            if (control.IsValid)
            {
                var finger = control.GetFingerPrintControl();
                finger.ClearFingerCount();
                Console.WriteLine(finger.GetFingerCount());
            }
        }



        private void webRTCToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowserList.data[0].GetMainFrame().LoadURL("https://browserleaks.com/webrtc");
        
        }
    }
}
